package com.blog.backend.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.blog.backend.annotation.LoginAnno;
import com.blog.backend.domain.BlogAccess;
import com.blog.backend.resp.*;
import com.blog.backend.service.BlogIndexManagerService;
import com.blog.backend.utils.HttpUtils;
import com.blog.backend.utils.PageUtils;
import com.blog.backend.utils.Result;
import com.blog.backend.vo.PageRequest;
import com.blog.backend.vo.PageResult;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.List;

import static org.bouncycastle.asn1.x500.style.RFC4519Style.o;

@Controller
@ResponseBody
@RequestMapping("/blog/index")
public class BlogIndexController {

    @Autowired
    private BlogIndexManagerService blogIndexManagerService;

    @GetMapping("/statisticsTotal")
    @LoginAnno
    @ApiOperation("统计首页各类文章总数")
    public Result<StatisticsNumResp> statisticsTotal(){
      StatisticsNumResp total= blogIndexManagerService.statisticsTotal();
      return Result.success(total);
    }


    @GetMapping("/selectTenAccess")
    @LoginAnno
    @ApiOperation("查询最新的十条评论")
    public Result<List<BlogAccess>> selectTenAccess(){
        List<BlogAccess> list = blogIndexManagerService.selectTenAccess();
        return Result.success(list);
    }

    @GetMapping("/selectHotArticle")
    @LoginAnno
    @ApiOperation("最热门的文章列表")
    public Result<List<IndexArticleResp>> selectHotArticle(){
        List<IndexArticleResp> list=blogIndexManagerService.selectHotArticle(2);
        return Result.success(list);
    }

    @GetMapping("/selectDraftNums")
    @LoginAnno
    @ApiOperation("查看草稿列表")
    public Result<DraftResp> selectDraftNums(){
        DraftResp resp = blogIndexManagerService.selectDraftNums();
        return Result.success(resp);
    }

    @GetMapping("/selectTitleData")
    @LoginAnno
    @ApiOperation("查看首页额外信息")
    public Result<TitleDataResp> selectTitleData(){
        TitleDataResp resp=blogIndexManagerService.selectTitleData();
        return Result.success(resp);
    }


}
